package appLoader.data {
	
	public class HashTable {
		
		protected var _keys		:Array;
		protected var _values	:Array;
		
		public function HashTable() {
			_keys 	= new Array();
			_values = new Array();
		}
		
		public function put(key : Object, value : Object):void {
			var index : Number = _keys.indexOf (key);
			if (index > - 1) {
				_values[index] = value;
			} else {
				_keys.push(key);
				_values.push(value);
			}
		}
		
		public function removeByKey(key:Object):Object{
			var index:Number = _keys.indexOf(key)
			if(index >-1){
				return removeByIndex(index)
			}
			return null
		}
		public function removeByValue(value:Object):Object{
			var index:Number = _values.indexOf(value);
			if(index >-1){
				return removeByIndex(index)
			}
			return null
		}
		public function removeByIndex(index: int): Object{
			if (index < length()) {
				_keys.splice(index,1)
				return _values.splice(index,1)
			} else {
				return null;
			}
		}
		
		//
		public function getKey(value : Object):Object {
			var index : Number = _values.indexOf (value);
			if (index > - 1) {
				return _keys[index];
			} else {
				return (null);
			}
		}
		//
		public function getValueByIndex(index : Number):Object {
			if (index < length()) {
				return _values[index];
			} else {
				return null;
			}
		}
		//
		public function getKeyByIndex(index : Number):Object {
			if (index < length()) {
				return _keys[index];
			} else {
				return null;
			}
		}
		//
		public function get(key : Object):Object {
			return getValue(key);
		}
		//
		public function getValue(key : Object):Object {
			var index : Number = _keys.indexOf(key);
			if (index > - 1) {
				return _values[index];
			} else {
				return null;
			}
		}
		//
		public function getValues():Array{
			return _values
		}
		public function getKeys():Array{
			return _keys
		}
		//
		public function clear(): void{
			_keys = new Array();
			_values = new Array();
		}
		//
		public function length():int {
			return int(_keys.length);
		}
		public function has(key:Object):Boolean {
			return _keys.indexOf(key) > -1;
		}
		public function indexOf(key:Object):int {
			return _keys.indexOf(key);
		}
		public function isEmpty(): Boolean{
			return	_keys.length > 0
		}
	}
}
